using Microsoft.Extensions.Hosting.WindowsServices;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using test.Models;

var options = new WebApplicationOptions
{
    Args = args,
    ContentRootPath = WindowsServiceHelpers.IsWindowsService()
                                     ? AppContext.BaseDirectory : default
};



var builder = WebApplication.CreateBuilder(options);

// Add services to the container.

builder.Services.AddControllers();

builder.Services.AddDbContext<hongjiContext>(optioin =>
{
    string ConnString = builder.Configuration.GetConnectionString("MySqlConnection");
    var serverVersion = ServerVersion.AutoDetect(ConnString);
    optioin.UseMySql(ConnString, serverVersion);
});


// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(u => {
    u.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
    {
        Version = "Ver:1.0",
        Title = "BackStageAPI",
        Description = "Using in Website"
    });
});



builder.Host.UseWindowsService();

builder.Services.AddCors(options =>
{
    options.AddPolicy("any", builder =>
    {
        builder.SetIsOriginAllowed(_ => true).AllowAnyMethod().AllowAnyHeader().AllowCredentials();
    });
});

var app = builder.Build();

app.UseCors("any");

app.UseSwagger();
app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebSite API V1");
    //  /swagger/index.html
}
);

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
}

//app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

//app.Urls.Add("http://localhost:5000");


app.Run();


public interface IMyDependency
{
    void WriteMessage(string message);
}